package com.dao.impl;

import com.dao.MenusDao;
import com.uilt.JdbcUtil;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class MenusDaoImpl implements MenusDao {
    @Override
    public ResultSet getMenusAll(int uid,int type) {
        String sql=" SELECT * FROM ( SELECT * FROM dy_role_resources  \n" +
                "                WHERE rid IN(SELECT rid FROM dy_user_role  WHERE uid=?)) meu \n" +
                "                LEFT JOIN dy_resources dymenu\n" +
                "                ON meu.resid=dymenu.id \n" +
                "                WHERE TYPE=?";
        List<Object> list = new ArrayList<Object>();
        list.add(uid);
        list.add(type);
        ResultSet object = JdbcUtil.getObject(list, sql);
        return object;
    }

    @Override
    public ResultSet getMenusAll() {
        String sql=" SELECT * FROM dy_resources";
        List<Object> list = new ArrayList<Object>();
        ResultSet object = JdbcUtil.getObject(list, sql);
        return object;
    }

    @Override
    public ResultSet getMenusBtn(int uid, int pid, int type) {
        String sql=" SELECT * FROM ( SELECT * FROM dy_role_resources  \n" +
                "                WHERE rid IN(SELECT rid FROM dy_user_role  WHERE uid=?)) meu \n" +
                "                LEFT JOIN dy_resources dymenu\n" +
                "                ON meu.resid=dymenu.id \n" +
                "               WHERE parentId=? AND TYPE=?";
        List<Object> list = new ArrayList<Object>();
        list.add(uid);
        list.add(pid);
        list.add(type);
        ResultSet object = JdbcUtil.getObject(list, sql);
        return object;
    }

    @Override
    public ResultSet getBtn() {
        String sql=" SELECT * FROM dy_button";
        List<Object> list = new ArrayList<Object>();
        ResultSet object = JdbcUtil.getObject(list, sql);
        return object;
    }
}
